package com.szpx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szpx.entity.LJK.LJKCoach;
import com.szpx.entity.LJK.Reserve;
import com.szpx.mapper.LJKReserveMapper;
import com.szpx.service.LJKCoachService;
import com.szpx.service.LJKReserveService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LJKReserveServiceImpl implements LJKReserveService {
    @Resource
    private LJKReserveMapper ljkReserveMapper;
    @Resource
    private LJKCoachService ljkCoachService;
    // 这里可以实现具体的预约服务逻辑
    // 例如，处理预约教练、查询预约记录等方法

    // 示例方法：预约教练
    @Override
    public boolean reserveCoach(Reserve reserve){
        return ljkReserveMapper.insert(reserve) > 0;
    }

    @Override
    public PageInfo<Reserve> queryAllReserve(Integer page, Integer limit, Reserve reserve) {
        PageHelper.startPage(page, limit);
        List<Reserve> reserves = ljkReserveMapper.selectAll(reserve);
        reserves.forEach(r->{
            LJKCoach coach = ljkCoachService.getCoachById(r.getCoachId());
            r.setCoachName(coach.getName());
        });
        return new PageInfo<>(reserves);
    }

    @Override
    public boolean updateStatus(Long id, int status) {
        return ljkReserveMapper.updateStatus(id, status) > 0;
    }

    // 示例方法：取消预约
    public boolean cancelReservation(Long reservationId) {
        // 实现取消预约逻辑
        return true; // 返回取消成功或失败
    }
}
